package com.bmps.springcloud.insuredmicroservice.service.amnt.strategy;

import com.bmps.springcloud.common.utils.DateUtil;
import com.bmps.springcloud.insuredmicroservice.constant.accept.AcceptConstant;
import com.bmps.springcloud.insuredmicroservice.constant.accept.UnderWriteConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.InsurantModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.ProductModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.RequestModel;
import com.bmps.springcloud.insuredmicroservice.model.trail.TrialPersonModel;
import com.bmps.springcloud.insuredmicroservice.service.RedisService;
import com.bmps.springcloud.insuredmicroservice.util.accept.AcceptUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author Administrator
 * @date 2021/3/1715:55
 */
public class Net009AmntStrategy implements AmntStrategy {
    /**
     * @param productModel 产品对象
     * @param requestModel 报文请求对象
     * @param redisService 操作缓存对象
     * @return
     */
    @Override
    public TrialPersonModel amntTrialCalculation(ProductModel productModel, RequestModel requestModel, RedisService redisService) {
        List<InsurantModel> insurantModelList = requestModel.getCustInfo().getInsurants().getInsurant();
        InsurantModel insurantModel = AcceptUtil.getInsurantModelBySeq(productModel.getProdInsSeq(), insurantModelList);
        TrialPersonModel trialPersonModel = new TrialPersonModel();
        trialPersonModel.setRiskCode(productModel.getProdCode());
        trialPersonModel.setPrem(productModel.getPrem());
        String payIntv = requestModel.getProductInfo().getPayIntv();
        if (StringUtils.equals(UnderWriteConstant.MONTH_PAY, payIntv)) {
            trialPersonModel.setPayIntvRate("0.085");
            trialPersonModel.setPayIntv("12");
        } else {
            trialPersonModel.setPayIntvRate("1");
            trialPersonModel.setPayIntv(payIntv);
        }

        trialPersonModel.setPayEndYear(productModel.getPayYear());
        trialPersonModel.setInsuYear(productModel.getInsureYear());
        trialPersonModel.setAppAge(DateUtil.getYears(insurantModel.getBirthday(), requestModel.getPolicyInfo().getPolApplyDate()));
        trialPersonModel.setSex(insurantModel.getSex());
        trialPersonModel.setGetYear(requestModel.getProductInfo().getGetYear());

        trialPersonModel = redisService.getCalculateModeNew(trialPersonModel, AcceptConstant.CALCULATION_TYPE_P);
        return trialPersonModel;
    }
}
